package com.kpx.app.view;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
import android.widget.ViewFlipper;

/**
 * 监听滑动的webview
 * 
 * @Description TODO
 * @author yanzhong
 * @date 2015年5月26日
 * @Copyright: Copyright (c) 2015 Shenzhen Tentinet Technology Co., Ltd. Inc. All rights reserved.
 */
public class MyWebView extends WebView {

	private ScrollInterface scrollInterface;

	private ViewFlipper flipper;
	private int CurrentPage;
	private int CommentPage;
	Context mContext;

	private float lastTouchX;
	private float lastTouchY;

	private Boolean CanShowNext;

	public Boolean getCanShowNext() {
		return CanShowNext;
	}

	public void setCanShowNext(Boolean canShowNext) {
		CanShowNext = canShowNext;
	}

	public Boolean getCanShowPrevious() {
		return CanShowPrevious;
	}

	public void setCanShowPrevious(Boolean canShowPrevious) {
		CanShowPrevious = canShowPrevious;
	}

	private Boolean CanShowPrevious;

	/**
	 * 定义滑动接口
	 * 
	 * @Description TODO
	 * @author yanzhong
	 * @date 2015年5月26日
	 * @Copyright: Copyright (c) 2015 Shenzhen Tentinet Technology Co., Ltd. Inc. All rights reserved.
	 */
	public interface ScrollInterface {
		public void onSChanged(int l, int t, int oldl, int oldt);
	}

	public MyWebView(Context context) {
		super(context);
		mContext = context;
		this.CanShowNext = false;
		this.CanShowPrevious = false;
		if (Build.VERSION.SDK_INT >= 19) {
			getSettings().setLoadsImagesAutomatically(true);
		} else {
			getSettings().setLoadsImagesAutomatically(false);
		}
	}

	public MyWebView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		if (Build.VERSION.SDK_INT >= 19) {
			getSettings().setLoadsImagesAutomatically(true);
		} else {
			getSettings().setLoadsImagesAutomatically(false);
		}
	}

	public MyWebView(Context context, AttributeSet attrs) {
		super(context, attrs);
		if (Build.VERSION.SDK_INT >= 19) {
			getSettings().setLoadsImagesAutomatically(true);
		} else {
			getSettings().setLoadsImagesAutomatically(false);
		}
	}

	public MyWebView(Context context, ViewFlipper flipper) {
		super(context);
		mContext = context;
		this.flipper = flipper;
		this.CanShowNext = false;
		this.CanShowPrevious = false;
		if (Build.VERSION.SDK_INT >= 19) {
			getSettings().setLoadsImagesAutomatically(true);
		} else {
			getSettings().setLoadsImagesAutomatically(false);
		}
	}

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		super.onScrollChanged(l, t, oldl, oldt);
		if (scrollInterface != null) {
			scrollInterface.onSChanged(l, t, oldl, oldt);
		}
	}

	public void setOnCustomScroolChangeListener(ScrollInterface t) {
		this.scrollInterface = t;
	}

	public float getLastTouchX() {
		return lastTouchX;
	}

	public void setLastTouchX(float lastTouchX) {
		this.lastTouchX = lastTouchX;
	}

	public float getLastTouchY() {
		return lastTouchY;
	}

	public void setLastTouchY(float lastTouchY) {
		this.lastTouchY = lastTouchY;
	}

	public int getCurrentPage() {
		return CurrentPage;
	}

	public void setCurrentPage(int currentPage) {
		CurrentPage = currentPage;
	}

	public int getCommentPage() {
		return CommentPage;
	}

	public void setCommentPage(int commentPage) {
		CommentPage = commentPage;
	}

}
